//
//  PhotoViewController.m
//  Movie
//
//  Created by tengyang on 15/7/23.
//  Copyright (c) 2015年 tengyang. All rights reserved.
//

#import "PhotoViewController.h"
#import "PhotoCollectionView.h"

@interface PhotoViewController ()

@end

@implementation PhotoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self _createNav];
    [self _createCollectionView];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(navHidden) name:@"hiddenNav" object:nil];
    
}

- (void)navHidden
{
    BOOL ishidden= self.navigationController.navigationBar.isHidden;
    self.navigationController.navigationBarHidden=!ishidden;
}

- (void)_createCollectionView
{
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
    layout.itemSize=self.view.frame.size;
    layout.scrollDirection=UICollectionViewScrollDirectionHorizontal;
    layout.minimumLineSpacing=30;
    _collectionView =[[PhotoCollectionView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width+30, [UIScreen mainScreen].bounds.size.height) collectionViewLayout:layout];
    
    [self.view addSubview:_collectionView];
    
    
    
    
}

- (void)setImageUrlArray:(NSMutableArray *)imageUrlArray
{
    _imageUrlArray=imageUrlArray;
    _collectionView.imageUrl=_imageUrlArray;
    
    //实现了点击那幅图片就出现那幅图片
    NSIndexPath *path=[NSIndexPath indexPathForRow:_index inSection:0];
    [_collectionView scrollToItemAtIndexPath:path atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
}

-(void)_createNav
{
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancelAction)];
}

- (void)cancelAction
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
